package com.sky.web.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;


import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 员工管理
 */
@Slf4j
@RestController
@RequestMapping("/admin/employee")
@Api(tags = "员工相关接口")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/login")
    @ApiOperation("员工登录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "EmployeeLoginDTO",value = "员工登录DTO",required = true)
    )
    public Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO){
       EmployeeLoginVO employeeLoginVO = employeeService.login(employeeLoginDTO);

        return Result.success(employeeLoginVO);
    }

    @PostMapping("/logout")
    @ApiOperation("员工登出")
    public Result logout(){
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("员工登分页查询")
    public Result findByPage(EmployeePageQueryDTO employeePageQueryDTO){
        PageResult result = employeeService.findByPage(employeePageQueryDTO);
        return Result.success(result);
    }

    @PostMapping
    public Result save(@RequestBody EmployeeDTO employeeDTO){

        employeeService.save(employeeDTO);

        return Result.success();
    }

    @GetMapping("{id}")
    public Result findById(@PathVariable Long id){
       Employee employee = employeeService.findById(id);
       return Result.success(employee);
    }

    @PutMapping
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        employeeService.update(employeeDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,@RequestParam Long id){
        employeeService.updateStatus(status,id);
        return Result.success();
    }
}
